package com.example.security.util;

import com.google.gson.Gson;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;

public class CustomResponseEntity {
  private static final Gson gson = new Gson();

  public static void toJson(
      HttpServletResponse response, Integer statusCode, Integer code, String msg)
      throws IOException {
    var r = new HashMap<String, Object>();
    r.put("code", code);
    r.put("msg", msg);
    response.setStatus(statusCode);
    response.setCharacterEncoding("UTF-8");
    response.setContentType("application/json, charset=utf-8");
    response.getWriter().write(gson.toJson(r));
  }
}
